Fix wake lock re-acquisition on visibility change#25
Merged
Conversation
The wake lock was requested when entering the workout screen, but the visibilitychange handler never re-acquired it after the page became visible again. On iOS, switching apps releases the wake lock, so the screen would time out after returning to the workout. Track whether a wake lock is actively wanted and re-request it on visibility change. https://claude.ai/code/session_01MgxBE65U2FSemXB1CKtdZF
…e test The test was flaky because it reloaded the page immediately after checking the intersperse checkbox, without waiting for the async putSettings() IndexedDB write to complete. Add a waitForFunction that reads directly from IndexedDB to confirm the write landed. https://claude.ai/code/session_01MgxBE65U2FSemXB1CKtdZF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the wake lock re-acquisition logic to properly handle visibility changes while preventing unnecessary re-requests after explicit release.
Key Changes
wakeLockActiveflag to track whether wake lock should be maintained across visibility changeswakeLockActive = truewhenrequestWakeLock()is calledwakeLockActive = falsewhenreleaseWakeLock()is calledvisibilitychangeevent listener to re-acquire wake lock only when the page becomes visible ANDwakeLockActiveis trueImplementation Details
The fix introduces a state flag (
wakeLockActive) that distinguishes between:This ensures the wake lock is properly maintained during app switching (e.g., on iOS) while respecting user navigation that should release the lock.
https://claude.ai/code/session_01MgxBE65U2FSemXB1CKtdZF